//
//  CTFollowView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/5/23.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTFollowView.h"
#import "CTDebugManager.h"
#import "CTHeader.h"
#import "CTFollowCell.h"
#import "CTDiscoveryItems.h"
#import "CTDeviceFunction.h"
#import "CTDataGenerator.h"
#import "CTAppLanguage.h"
#import "UIViewAdditions.h"
#import "RefreshControl.h"

@interface CTFollowView()<UITableViewDataSource,UITableViewDelegate,CTFollowCellDelegate>
{
    NSMutableArray      *followMutableArray;
    UITableView         *followTableView;
    UIView              *topView;
    NSMutableArray * recommendListMutableArray;

}

@end

@implementation CTFollowView

- (void)dealloc
{
    recommendListMutableArray = nil;
    followMutableArray = nil;
    [followTableView removeFromSuperview];
    followTableView = nil;
    [topView removeFromSuperview];
    topView = nil;
    [CTDebugManager showDebugLogInfo:@"dealloc : CTFollowView Is Removed!!!"];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self createTitlView];
        [self createUserFavoriteListTableView];
    }
    return self;
}

- (void)createTitlView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
//    topView.alpha = 0.8;
    [self addSubview:topView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"discoveryView_title_text" withValue:nil withTable:@"Language"];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.font = [UIFont fontWithName:nil size:21];
    [topView addSubview:titleLabel];
    UILabel *topLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topLine];
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
//    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    backButton.frame = CGRectMake(0, 20, 44, 44);
//    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
//    [backButton setImage:[UIImage imageNamed:@"login_icon_back"] forState:UIControlStateNormal];
//    [backButton setImage:[UIImage imageNamed:@"login_icon_back_click"] forState:UIControlStateHighlighted];
//    [topView addSubview:backButton];
    
}
//- (void)backButtonAction:(UIButton *) sender
//{
//    if ([self.delegate respondsToSelector:@selector(userFollowTableViewBackBtnAction:)])
//    {
//        [self.delegate userFollowTableViewBackBtnAction:self];
//    }
//}

- (void)createUserFavoriteListTableView
{
    followTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, topView.bottom, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-64-50) style:UITableViewStylePlain];
    followTableView.delegate = self;
    followTableView.dataSource = self;
    followTableView.showsVerticalScrollIndicator = YES;
    followTableView.backgroundColor = [UIColor redColor];
    followTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    followTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    followTableView.backgroundColor = [UIColor whiteColor];
    [followTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self addSubview:followTableView];
    
}
#pragma mark-UITableViewDataSource
//分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section == 0)
    {
        if(followMutableArray.count >0)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    if (section == 1)
    {
        return followMutableArray.count;
    }
    
    return 0;
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    CTFollowCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[CTFollowCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        cell.delegate = self;
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CTFollowList * item = [followMutableArray objectAtIndex:indexPath.row];
    cell.cellItem = item;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    
    if (indexPath.section ==0)
    {
        
    }
}
#pragma  mark -setter- 
- (void)setFollowArray:(NSArray *)followArray
{
    followMutableArray = [followArray mutableCopy];
}

- (void)setUserRecommendDataArray:(NSArray *)recommendListArray
{
    recommendListMutableArray = [recommendListArray mutableCopy];
}

#pragma mark - CTFollowCellDelegate -
/**
 *@brief 点击评论总数
 */
- (void)userPublishTableCellCommentCountAction:(CTFollowCell *)cell withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewCommentCountAction:withItem:)])
    {
        [self.delegate followViewCommentCountAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第一条
 */
- (void)userPublishTableCellCommentHitFirstLabelAction:(CTFollowCell *) cell withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewCommentHitFirstLabelAction:withItem:)])
    {
        [self.delegate followViewCommentHitFirstLabelAction:self withItem:item];
    }

}
/**
 *@brief 点击评论第二条
 */
- (void)userPublishTableCellCommentHitSecondLabelAction:(CTFollowCell *) cell withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewCommentHitSecondLabelAction:withItem:)])
    {
        [self.delegate followViewCommentHitSecondLabelAction:self withItem:item];
    }

}
/**
 *@brief 点击评论第一条头像
 */
- (void)userPublishTableCellCommentHitFirstHeadAction:(CTFollowCell *)cell withItem:(CTComment *) item
{
    if ([self.delegate respondsToSelector:@selector(followViewCommentHitFirstHeadAction:withItem:)])
    {
        [self.delegate followViewCommentHitFirstHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击评论第二条头像
 */
- (void)userPublishTableCellCommentHitSecondHeadAction:(CTFollowCell *)cell withItem:(CTComment *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewCommentHitSecondHeadAction:withItem:)])
    {
        [self.delegate followViewCommentHitSecondHeadAction:self withItem:item];
    }
}
/**
 *@brief 点击头像
 */
- (void)userPublishTableCellHitHeadAction:(CTFollowCell *)cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitHeadAction:withItem:)])
    {
        [self.delegate followViewHitHeadAction:self withItem:item];
    }

}
/**
 *@brief 点击大图
 */
- (void)userPublishTableCellHitPicImageBtnAction:(CTFollowCell *)cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitPicImageBtnAction:withItem:)])
    {
        [self.delegate followViewHitPicImageBtnAction:self withItem:item];
    }

}
/**
 *@brief 点赞
 */
- (void)userPublishTableCellHitFavourBtnAction:(CTFollowCell *)cell withItem:(CTFollowList *)item withBool:(BOOL) favBool
{
    if ([self.delegate respondsToSelector:@selector(followViewHitFavBtnHeadAction:withItem:)])
    {
        [self.delegate followViewHitFavourBtnAction:self withItem:item withBool:favBool];
    }
}
/**
 *@brief 点击评论按钮
 */
- (void)userPublishTableCellHitCommentBtnaction:(CTFollowCell *) cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitCommentBtnaction:withItem:)]) {
        [self.delegate followViewHitCommentBtnaction:self withItem:item];
    }

}
/**
 *@brief 点击分享按钮
 */
- (void)userPublishTableCellHitShareBtnAction:(CTFollowCell *) cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitShareBtnAction:withItem:)])
    {
        [self.delegate followViewHitShareBtnAction:self withItem:item];
    }
}
/**
 *@brief 点击更多按钮
 */
- (void)userPublishTableCellHitMoreBtnAction:(CTFollowCell *) cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitMoreBtnAction:withItem:)]) {
        [self.delegate followViewHitMoreBtnAction:self withItem:item];
    }
}
/**
 *@brief 点击点赞的人的头像
 */
- (void)userPublishTableCellHitFavBtnHeadAction:(CTFollowCell *)cell withItem:(CTListDetailUser *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitFavBtnHeadAction:withItem:)])
    {
        [self.delegate followViewHitFavBtnHeadAction:self withItem:item];
    }

}
/**
 *@brief 点击关注按钮
 */
- (void)userPublishTableCellHitAttentionBtnAction:(CTFollowCell *) cell withItem:(CTFollowList *)item withBool:(BOOL)attentionBool
{
    if ([self.delegate respondsToSelector:@selector(followViewHitAttentionBtnAction:withItem:withBool:)])
    {
        [self.delegate followViewHitAttentionBtnAction:self withItem:item withBool:attentionBool];
    }

}
/**
 *@brief 点击话题
 */
- (void)userPublishTableCellHitTopicBtnAction:(CTFollowCell *) cell withItem:(CTFollowList *)item
{
    if ([self.delegate respondsToSelector:@selector(followViewHitTopicBtnAction:withItem:)])
    {
        [self.delegate followViewHitTopicBtnAction:self withItem:item];
    }

}
@end
